home *** CD-ROM | disk | FTP | other *** search
/ PC Elektro 3 / PC-Elektro-3-cd1.bin / KBan 2.0 / KBANSRC.LZH / SRC / PROG / NETLIST / NETLIST.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1997-08-23  |  3.7 KB  |  127 lines

  1. // the implementation of netlist-related functions
  2. // Copyright (C) 1997 Kazutaka Hirata <khirata@jove.acs.unt.edu>
  3.  
  4. #include <list>
  5. #include <vector>
  6. #include <string.h>
  7. #include "../finfo.h"
  8. #include "nitable.h"
  9.  
  10. #include "netlist.h"
  11.  
  12. void NETLIST_ERROR::not_distinct(const char* comp_name)
  13. {
  14. }
  15.  
  16. class NET_ELEMENT {
  17.   std::string m_designator;
  18.   uint        m_pin_number;
  19. public:
  20.   NET_ELEMENT() {}
  21.   NET_ELEMENT(const char* designator, uint pin_number)
  22.     : m_designator(designator),
  23.       m_pin_number(pin_number) {}
  24.   NET_ELEMENT(const NET_ELEMENT& elem)
  25.     : m_designator(elem.m_designator),
  26.       m_pin_number(elem.m_pin_number) {}
  27.  
  28.   const NET_ELEMENT& operator=(const NET_ELEMENT& rval) {
  29.     m_designator = rval.m_designator;
  30.     m_pin_number = rval.m_pin_number;
  31.     return *this;
  32.   }
  33.   bool operator==(const NET_ELEMENT& rval) const; // illegal (undefined)
  34.   bool operator!=(const NET_ELEMENT& rval) const; // illegal (undefined)
  35.   bool operator<(const NET_ELEMENT& rval) const; // illegal (undefined)
  36.   bool operator>(const NET_ELEMENT& rval) const; // illegal (undefined)
  37.  
  38.   const char* designator() const { return m_designator.c_str(); }
  39.   uint pin_number() const { return m_pin_number; }
  40. };
  41.  
  42. class NET_ELEMENT_LIST : public std::list<NET_ELEMENT> {
  43. public:
  44.   void GetParticularNet(int net, const KBAN_DATA& kban_data) {
  45.     const COMPONENT_LIST& component_list = kban_data.component_list();
  46.     COMPONENT_LIST::iterator i;
  47.     TRAVERSE(component_list, i) {
  48.       const COMPONENT_ELEMENT& component_element = *i;
  49.       for(uint j = 0; j < LAYER_NUMBER; j++) {
  50.         const LAYER& layer = component_element.layer(j);
  51.         const PIN_LIST& pin_list = layer.pin_list();
  52.         PIN_LIST::iterator k;
  53.         TRAVERSE(pin_list, k) {
  54.           const PIN_ELEMENT& pin_element = *k;
  55.           if(pin_element.net_number() == net) {
  56.             NET_ELEMENT elem(component_element.designator(), pin_element.number());
  57.             push_back(elem);
  58.           }
  59.         }
  60.       }
  61.     }
  62.   }
  63. };
  64.  
  65. bool are_distinct_component_names(NETLIST_ERROR& ne, const KBAN_DATA& kban_data)
  66. {
  67.   const COMPONENT_LIST& comp_list = kban_data.component_list();
  68.   uint size = comp_list.size();
  69.  
  70.   COMPONENT_LIST::iterator i;
  71.   uint j = 0;
  72.   std::vector<const char *> designator_table(size);
  73.   TRAVERSE(comp_list, i) {
  74.     designator_table[j] = i->designator();
  75.     j++;
  76.   }
  77.  
  78.   bool bDistinct = true;
  79.   for(uint k = 0; k < size; k++) {
  80.     for(uint l = 0; l < k; l++) {
  81.       if(!strcmp(designator_table[k], designator_table[l])) {
  82.         ne.not_distinct(designator_table[k]);
  83.         bDistinct = false;
  84.       }
  85.     }
  86.   }
  87.  
  88.   return bDistinct;
  89. }
  90.  
  91. void output_netlist(NETLIST_ERROR& ne, const char* fname, KBAN_DATA& kban_data)
  92. {
  93.   FILE_NEW fp(fname, "w");
  94.  
  95. #if 0
  96.   if(!are_distinct_component_names(ne, kban_data)) {
  97.     fp.printf("Not Distinct\n");
  98.   }
  99. #endif
  100.  
  101.   NET_ITEM_TABLE net_item_table;
  102.   net_item_table.AddItem(kban_data);
  103.   net_item_table.ResetAllConnections();
  104.   net_item_table.GenerateNetlist(LAYER_PATTERN_TOP   );
  105.   net_item_table.GenerateNetlist(LAYER_PATTERN_BOTTOM);
  106.   net_item_table.SetFinalNumber();
  107.  
  108.   for(uint i = 0, j = 1; i < net_item_table.size(); i++) {
  109.     if(net_item_table.IsRoot(i)) {
  110.       NET_ELEMENT_LIST net_elem_list;
  111.       net_elem_list.GetParticularNet(i, kban_data);
  112.       if(net_elem_list.size() != 0) {
  113.         fp.printf("net number %3d :\n", j);
  114.         NET_ELEMENT_LIST::iterator k;
  115.         for(k = net_elem_list.begin(); k != net_elem_list.end(); k++) {
  116.           const NET_ELEMENT& current_elem = *k;
  117.           fp.printf(" %5s %3d\n",
  118.             current_elem.designator(),
  119.             current_elem.pin_number()
  120.           );
  121.         }
  122.         j++;
  123.       }
  124.     }
  125.   }
  126. }
  127.